#################################################################################
#	REPLICATION SCRIPT								
#	When Marriage Gets Hard: Intra-Coalition Conflict and Electoral Accountability
# Carolina Plescia (carolina.plescia@univie.ac.at)					
#	THIS VERSION: 14-04-2021							
#											                              	                          #
#	NOTE:	This script allows to reproduce all numerical results 
#       presented in the Online-only Appendix.
#################################################################################




#Remember to set local working directory
setwd("~/replication files")

#Load required packages
library(rms)
library(texreg)
library(interplot)
library(interactions)
library(tidyverse)
library(dplyr)
library(jtools)


#Load required datasets
load("data.RData")

# All variables, except for binary variables, 
# are standardised by centring and dividing by two standard deviations (Gelman 2008)

"Negative economic perceptions"
data$eco_retro_R<-rescale(data$eco_retro, "full")
summary(data$eco_retro_R)

"Intra-coalition conflict"
data$mean_conflict_REV_R<-rescale(data$mean_conflict_REV, "full")
summary(data$mean_conflict_REV_R)

"Political sophistication"
data$pol_sophi_R<-rescale(data$pol_sophi, "full")
summary(data$pol_sophi_R)

"Days in governemnt"
data$days_int_elec_R<-rescale(data$days_int_elec, "full")
summary(data$days_int_elec_R)

"Powell-Whitten index"
data$PWindex_R<-rescale(data$PWindex, "full")
summary(data$PWindex_R)

"Institutional clarity index"
data$Insti_clarity_R<-rescale(data$Insti_clarity, "full")
summary(data$Insti_clarity_R)

"Government clarity index"
data$Gov_clarity_R<-rescale(data$Gov_clarity, "full")
summary(data$Gov_clarity_R)

"Age"
data$age_R<-rescale(data$age, "full")
summary(data$age_R)

#Correlation checks

cor(data$PWindex_R,data$Insti_clarity_R, use="complete.obs")
cor(data$PWindex_R,data$Gov_clarity_R, use="complete.obs")
cor(data$Insti_clarity_R,data$Gov_clarity_R, use="complete.obs")

cor(data$mean_conflict_REV_R, data$PWindex_R, use="complete.obs")
cor(data$mean_conflict_REV_R, data$Gov_clarity_R, use="complete.obs")
cor(data$mean_conflict_REV_R, data$Insti_clarity_R, use="complete.obs")

cor(data$mean_conflict_REV_R, data$earlytermination,use="complete.obs")
cor(data$mean_conflict_REV_R, data$minresignation,use="complete.obs")
cor(data$mean_conflict_REV_R, data$PMresignation,use="complete.obs")
cor(data$mean_conflict_REV_R, data$reshuffle,use="complete.obs")

data$PID_3cat.f <- factor(data$PID_3cat)
is.factor(data$PID_3cat.f)

data$cat_responsability.f <- factor(data$cat_responsability)
is.factor(data$cat_responsability.f)

data$cat_responsability.PM <- factor(data$cat_responsability_PM)
is.factor(data$cat_responsability.PM)

data$cat_responsability.J <- factor(data$cat_responsability_J)
is.factor(data$cat_responsability.J)





#############
#  TABLE S5	#
#############


ECO_modelPM.w=glmer(PM_vote ~ 1+eco_retro_R+mean_conflict_REV_R+cat_responsability_PM+
                      PID_3cat.f+age_R+female +PWindex_R+Insti_clarity_R+Gov_clarity_R+days_int_elec_R+
                      pol_sophi_R+(1|countrycode)+(1|countryNAME), data=data, family=binomial(link="logit"), control=glmerControl(optimizer="bobyqa"))

ECO_modelPM.3=glmer(PM_vote ~ 1+eco_retro_R*mean_conflict_REV_R*cat_responsability_PM+
                      PID_3cat.f+age_R+female +PWindex_R+Insti_clarity_R+Gov_clarity_R+days_int_elec_R+
                      pol_sophi_R+(1|countrycode)+(1|countryNAME), data=data, family=binomial(link="logit"), control=glmerControl(optimizer="bobyqa"))

ECO_modelJ.w=glmer(juniorPart_vote ~ 1+eco_retro_R+mean_conflict_REV_R+cat_responsability_J+
                     PID_3cat.f+age_R+female +PWindex_R+Insti_clarity_R+Gov_clarity_R+days_int_elec_R+
                     pol_sophi_R+(1|countrycode)+(1|countryNAME), data=data, family=binomial(link="logit"), control=glmerControl(optimizer="bobyqa"))

ECO_modelJ.3=glmer(juniorPart_vote ~ 1+eco_retro_R*mean_conflict_REV_R*cat_responsability_J+
                     PID_3cat.f+age_R+female +PWindex_R+Insti_clarity_R+Gov_clarity_R+days_int_elec_R+
                     pol_sophi_R+(1|countrycode)+(1|countryNAME), data=data, family=binomial(link="logit"), control=glmerControl(optimizer="bobyqa"))

screenreg(list(ECO_modelPM.w,ECO_modelPM.3, ECO_modelJ.w, ECO_modelJ.3), digits=3, booktabs = TRUE, dcolumn = TRUE)


htmlreg(list(ECO_modelPM.w, ECO_modelPM.3, ECO_modelJ.w, ECO_modelJ.3),
        custom.model.names = c("PM", "PM",
                               "JUNIOR", "JUNIOR"),
        custom.coef.names = c("(Intercept)", "Negative economic perceptions", "Intra-government conflict",
                              "PM responsability", 
                              "PM partisan", "Junior partisan","Opposition partisan", "Age",
                              "Female","Days in government", "Powell-Whitten index",  "Institutional clarity index",
                              "Government clarity index", "Political sophistication", "Perceptions x conflict",
                              "Perceptions x PM responsability", "Conflict x PM responsability", 
                              "Perceptions x conflict x PM responsability",
                              "Junior responsability", "Perceptions x Junior responsability",
                              "Conflict x Junior responsability", "Perceptions x conflict x Junior responsability"),
        reorder.coef = c(2:4, 15:22, 5:7, 10:13, 8:9, 14, 1), booktabs = TRUE, dcolumn = TRUE,
        groups = list("Controls" = 12:18, "Demographics" = 19:21),file = "tableS5.doc", digits=3)





#############
#  TABLE S6	#
#############

ECO_modelGOV=glmer(gov_vote ~ 1+eco_retro_R+mean_conflict_REV_R+
                     PID_3cat.f+age_R+female +PWindex_R+Insti_clarity_R+Gov_clarity_R+days_int_elec_R+
                     pol_sophi_R+(1|countrycode), data=data, family=binomial(link="logit"), control=glmerControl(optimizer="bobyqa"))

ECO_modelGOV.I=glmer(gov_vote ~ 1+eco_retro_R*mean_conflict_REV_R+
                       PID_3cat.f+age_R+female +PWindex_R+Insti_clarity_R+Gov_clarity_R+days_int_elec_R+
                       pol_sophi_R+(1|countrycode), data=data, family=binomial(link="logit"), control=glmerControl(optimizer="bobyqa"))


## MODELS --- PM 
ECO_modelPM=glmer(PM_vote ~ 1+eco_retro_R+mean_conflict_REV_R+
                    PID_3cat.f+age_R+female +PWindex_R+Insti_clarity_R+Gov_clarity_R+days_int_elec_R+
                    pol_sophi_R+(1|countrycode), data=data, family=binomial(link="logit"), control=glmerControl(optimizer="bobyqa"))

ECO_modelPM.I=glmer(PM_vote ~ 1+eco_retro_R*mean_conflict_REV_R+
                      PID_3cat.f+age_R+female +PWindex_R+Insti_clarity_R+Gov_clarity_R+days_int_elec_R+
                      pol_sophi_R+(1|countrycode), data=data, family=binomial(link="logit"), control=glmerControl(optimizer="bobyqa"))

## MODELS --- JUNIOR 
ECO_modelJ=glmer(juniorPart_vote ~ 1+eco_retro_R+mean_conflict_REV_R+
                   PID_3cat.f+age_R+female +PWindex_R+Insti_clarity_R+Gov_clarity_R+days_int_elec_R+
                   pol_sophi_R+(1|countrycode), data=data, family=binomial(link="logit"), control=glmerControl(optimizer="bobyqa"))

ECO_modelJ.I=glmer(juniorPart_vote ~ 1+eco_retro_R*mean_conflict_REV_R+
                     PID_3cat.f+age_R+female +PWindex_R+Insti_clarity_R+Gov_clarity_R+days_int_elec_R+
                     pol_sophi_R+(1|countrycode), data=data, family=binomial(link="logit"), control=glmerControl(optimizer="bobyqa"))

screenreg(list(ECO_modelGOV,ECO_modelGOV.I, ECO_modelPM,ECO_modelPM.I,
               ECO_modelJ, ECO_modelJ.I), booktabs = TRUE, dcolumn = TRUE,digits=3)

htmlreg(list(ECO_modelGOV,ECO_modelGOV.I, ECO_modelPM,ECO_modelPM.I,
             ECO_modelJ, ECO_modelJ.I),
        custom.model.names = c("GOVERNMENT", "GOVERNMENT",
                               "PM", "PM",
                               "JUNIOR", "JUNIOR"),
        custom.coef.names = c("(Intercept)", "Negative economic perceptions", "Intra-government conflict",
                              "PM partisan", "Junior partisan","Opposition partisan", "Age",
                              "Female","Days in government", "Powell-Whitten index",  "Institutional clarity index",
                              "Government clarity index", "Political sophistication", "Perceptions x conflict"),
        reorder.coef = c(2:3, 14, 4:6, 9:12,  7:8, 13, 1), booktabs = TRUE, dcolumn = TRUE,
        groups = list("Controls" = 4:10, "Demographics" = 11:13), 
        file = "tableS6.doc",digits=3)





#############
#  TABLE S7	#
#############

ECO_modelGOV=glmer(gov_vote ~ 1+eco_retro_R+mean_conflict_REV_R+
                     PID_3cat.f+age_R+female +PWindex_R+Insti_clarity_R+Gov_clarity_R+days_int_elec_R+
                     pol_sophi_R+(1|countryNAME), data=data, family=binomial(link="logit"), control=glmerControl(optimizer="bobyqa"))

ECO_modelGOV.I=glmer(gov_vote ~ 1+eco_retro_R*mean_conflict_REV_R+
                       PID_3cat.f+age_R+female +PWindex_R+Insti_clarity_R+Gov_clarity_R+days_int_elec_R+
                       pol_sophi_R+(1|countryNAME), data=data, family=binomial(link="logit"), control=glmerControl(optimizer="bobyqa"))


## MODELS --- PM 
ECO_modelPM=glmer(PM_vote ~ 1+eco_retro_R+mean_conflict_REV_R+
                    PID_3cat.f+age_R+female +PWindex_R+Insti_clarity_R+Gov_clarity_R+days_int_elec_R+
                    pol_sophi_R+(1|countryNAME), data=data, family=binomial(link="logit"), control=glmerControl(optimizer="bobyqa"))

ECO_modelPM.I=glmer(PM_vote ~ 1+eco_retro_R*mean_conflict_REV_R+
                      PID_3cat.f+age_R+female +PWindex_R+Insti_clarity_R+Gov_clarity_R+days_int_elec_R+
                      pol_sophi_R+(1|countryNAME), data=data, family=binomial(link="logit"), control=glmerControl(optimizer="bobyqa"))

## MODELS --- JUNIOR 
ECO_modelJ=glmer(juniorPart_vote ~ 1+eco_retro_R+mean_conflict_REV_R+
                   PID_3cat.f+age_R+female +PWindex_R+Insti_clarity_R+Gov_clarity_R+days_int_elec_R+
                   pol_sophi_R+(1|countryNAME), data=data, family=binomial(link="logit"), control=glmerControl(optimizer="bobyqa"))

ECO_modelJ.I=glmer(juniorPart_vote ~ 1+eco_retro_R*mean_conflict_REV_R+
                     PID_3cat.f+age_R+female +PWindex_R+Insti_clarity_R+Gov_clarity_R+days_int_elec_R+
                     pol_sophi_R+(1|countryNAME), data=data, family=binomial(link="logit"), control=glmerControl(optimizer="bobyqa"))

screenreg(list(ECO_modelGOV,ECO_modelGOV.I, ECO_modelPM,ECO_modelPM.I,
               ECO_modelJ, ECO_modelJ.I), booktabs = TRUE, dcolumn = TRUE,digits=3)

htmlreg(list(ECO_modelGOV,ECO_modelGOV.I, ECO_modelPM,ECO_modelPM.I,
             ECO_modelJ, ECO_modelJ.I),
        custom.model.names = c("GOVERNMENT", "GOVERNMENT",
                               "PM", "PM",
                               "JUNIOR", "JUNIOR"),
        custom.coef.names = c("(Intercept)", "Negative economic perceptions", "Intra-government conflict",
                              "PM partisan", "Junior partisan","Opposition partisan", "Age",
                              "Female","Days in government", "Powell-Whitten index",  "Institutional clarity index",
                              "Government clarity index", "Political sophistication", "Perceptions x conflict"),
        reorder.coef = c(2:3, 14, 4:6, 9:12,  7:8, 13, 1), booktabs = TRUE, dcolumn = TRUE,
        groups = list("Controls" = 4:10, "Demographics" = 11:13), 
        file = "tableS7.doc",digits=3)






#############
#  TABLE S8	#
#############


ECO_modelPM.w=glmer(PM_vote ~ 1+eco_retro_R+mean_conflict_REV_R+cat_responsability_PM+
                      PID_3cat.f+age_R+female +PWindex_R+Insti_clarity_R+Gov_clarity_R+days_int_elec_R+
                      pol_sophi_R+(1|countrycode), data=data, family=binomial(link="logit"), control=glmerControl(optimizer="bobyqa"))

ECO_modelPM.3=glmer(PM_vote ~ 1+eco_retro_R*mean_conflict_REV_R*cat_responsability_PM+
                      PID_3cat.f+age_R+female +PWindex_R+Insti_clarity_R+Gov_clarity_R+days_int_elec_R+
                      pol_sophi_R+(1|countrycode), data=data, family=binomial(link="logit"), control=glmerControl(optimizer="bobyqa"))

ECO_modelJ.w=glmer(juniorPart_vote ~ 1+eco_retro_R+mean_conflict_REV_R+cat_responsability_J+
                     PID_3cat.f+age_R+female +PWindex_R+Insti_clarity_R+Gov_clarity_R+days_int_elec_R+
                     pol_sophi_R+(1|countrycode), data=data, family=binomial(link="logit"), control=glmerControl(optimizer="bobyqa"))

ECO_modelJ.3=glmer(juniorPart_vote ~ 1+eco_retro_R*mean_conflict_REV_R*cat_responsability_J+
                     PID_3cat.f+age_R+female +PWindex_R+Insti_clarity_R+Gov_clarity_R+days_int_elec_R+
                     pol_sophi_R+(1|countrycode), data=data, family=binomial(link="logit"), control=glmerControl(optimizer="bobyqa"))

screenreg(list(ECO_modelPM.w,ECO_modelPM.3, ECO_modelJ.w, ECO_modelJ.3), digits=3, booktabs = TRUE, dcolumn = TRUE)


htmlreg(list(ECO_modelPM.w, ECO_modelPM.3, ECO_modelJ.w, ECO_modelJ.3),
        custom.model.names = c("PM", "PM",
                               "JUNIOR", "JUNIOR"),
        custom.coef.names = c("(Intercept)", "Negative economic perceptions", "Intra-government conflict",
                              "PM responsability", 
                              "PM partisan", "Junior partisan","Opposition partisan", "Age",
                              "Female","Days in government", "Powell-Whitten index",  "Institutional clarity index",
                              "Government clarity index", "Political sophistication", "Perceptions x conflict",
                              "Perceptions x PM responsability", "Conflict x PM responsability", 
                              "Perceptions x conflict x PM responsability",
                              "Junior responsability", "Perceptions x Junior responsability",
                              "Conflict x Junior responsability", "Perceptions x conflict x Junior responsability"),
        reorder.coef = c(2:4, 15:22, 5:7, 10:13, 8:9, 14, 1), booktabs = TRUE, dcolumn = TRUE,
        groups = list("Controls" = 12:18, "Demographics" = 19:21),file = "tableS8.doc", digits=3)




#############
#  TABLE S9	#
#############


ECO_modelPM.w=glmer(PM_vote ~ 1+eco_retro_R+mean_conflict_REV_R+cat_responsability_PM+
                      PID_3cat.f+age_R+female +PWindex_R+Insti_clarity_R+Gov_clarity_R+days_int_elec_R+
                      pol_sophi_R+(1|countryNAME), data=data, family=binomial(link="logit"), control=glmerControl(optimizer="bobyqa"))

ECO_modelPM.3=glmer(PM_vote ~ 1+eco_retro_R*mean_conflict_REV_R*cat_responsability_PM+
                      PID_3cat.f+age_R+female +PWindex_R+Insti_clarity_R+Gov_clarity_R+days_int_elec_R+
                      pol_sophi_R+(1|countryNAME), data=data, family=binomial(link="logit"), control=glmerControl(optimizer="bobyqa"))

ECO_modelJ.w=glmer(juniorPart_vote ~ 1+eco_retro_R+mean_conflict_REV_R+cat_responsability_J+
                     PID_3cat.f+age_R+female +PWindex_R+Insti_clarity_R+Gov_clarity_R+days_int_elec_R+
                     pol_sophi_R+(1|countryNAME), data=data, family=binomial(link="logit"), control=glmerControl(optimizer="bobyqa"))

ECO_modelJ.3=glmer(juniorPart_vote ~ 1+eco_retro_R*mean_conflict_REV_R*cat_responsability_J+
                     PID_3cat.f+age_R+female +PWindex_R+Insti_clarity_R+Gov_clarity_R+days_int_elec_R+
                     pol_sophi_R+(1|countryNAME), data=data, family=binomial(link="logit"), control=glmerControl(optimizer="bobyqa"))

screenreg(list(ECO_modelPM.w,ECO_modelPM.3, ECO_modelJ.w, ECO_modelJ.3), digits=3, booktabs = TRUE, dcolumn = TRUE)


htmlreg(list(ECO_modelPM.w, ECO_modelPM.3, ECO_modelJ.w, ECO_modelJ.3),
        custom.model.names = c("PM", "PM",
                               "JUNIOR", "JUNIOR"),
        custom.coef.names = c("(Intercept)", "Negative economic perceptions", "Intra-government conflict",
                              "PM responsability", 
                              "PM partisan", "Junior partisan","Opposition partisan", "Age",
                              "Female","Days in government", "Powell-Whitten index",  "Institutional clarity index",
                              "Government clarity index", "Political sophistication", "Perceptions x conflict",
                              "Perceptions x PM responsability", "Conflict x PM responsability", 
                              "Perceptions x conflict x PM responsability",
                              "Junior responsability", "Perceptions x Junior responsability",
                              "Conflict x Junior responsability", "Perceptions x conflict x Junior responsability"),
        reorder.coef = c(2:4, 15:22, 5:7, 10:13, 8:9, 14, 1), booktabs = TRUE, dcolumn = TRUE,
        groups = list("Controls" = 12:18, "Demographics" = 19:21),file = "tableS9.doc", digits=3)





###############
#  TABLE S10	#
###############


ECO_modelGOV=glmer(gov_vote ~ 1+eco_retro_R+mean_conflict_REV_R+
                     (1|countrycode)+(1|countryNAME), data=data, family=binomial(link="logit"), control=glmerControl(optimizer="bobyqa"))

ECO_modelGOV.I=glmer(gov_vote ~ 1+eco_retro_R*mean_conflict_REV_R+
                       (1|countrycode)+(1|countryNAME), data=data, family=binomial(link="logit"), control=glmerControl(optimizer="bobyqa"))

ECO_modelPM=glmer(PM_vote ~ 1+eco_retro_R+mean_conflict_REV_R+
                    (1|countrycode)+(1|countryNAME), data=data, family=binomial(link="logit"), control=glmerControl(optimizer="bobyqa"))

ECO_modelPM.I=glmer(PM_vote ~ 1+eco_retro_R*mean_conflict_REV_R+
                      (1|countrycode)+(1|countryNAME), data=data, family=binomial(link="logit"), control=glmerControl(optimizer="bobyqa"))

ECO_modelJ=glmer(juniorPart_vote ~ 1+eco_retro_R+mean_conflict_REV_R+
                   (1|countrycode)+(1|countryNAME), data=data, family=binomial(link="logit"), control=glmerControl(optimizer="bobyqa"))

ECO_modelJ.I=glmer(juniorPart_vote ~ 1+eco_retro_R*mean_conflict_REV_R+
                     (1|countrycode)+(1|countryNAME), data=data, family=binomial(link="logit"), control=glmerControl(optimizer="bobyqa"))

screenreg(list(ECO_modelGOV,ECO_modelGOV.I, ECO_modelPM,ECO_modelPM.I,
               ECO_modelJ, ECO_modelJ.I), booktabs = TRUE, dcolumn = TRUE,digits=3)

htmlreg(list(ECO_modelGOV,ECO_modelGOV.I, ECO_modelPM,ECO_modelPM.I,
             ECO_modelJ, ECO_modelJ.I),
        custom.model.names = c("GOVERNMENT", "GOVERNMENT",
                               "PM", "PM",
                               "JUNIOR", "JUNIOR"),
        custom.coef.names = c("(Intercept)", "Negative economic perceptions", "Intra-government conflict",
                              "Perceptions x conflict"),
        reorder.coef = c(2:4, 1), booktabs = TRUE, dcolumn = TRUE,
        file = "tableS10.doc",digits=3)




###############
#  TABLE S11	#
###############

ECO_modelGOV=glmer(gov_vote ~ 1+eco_retro_R+mean_conflict_REV_R+
                     PID_3cat.f+age_R+female +PWindex_R+Insti_clarity_R+Gov_clarity_R+days_int_elec_R+corporatism+
                     pol_sophi_R+(1|countrycode)+(1|countryNAME), data=data, family=binomial(link="logit"), control=glmerControl(optimizer="bobyqa"))

ECO_modelGOV.I=glmer(gov_vote ~ 1+eco_retro_R*mean_conflict_REV_R+
                       PID_3cat.f+age_R+female +PWindex_R+Insti_clarity_R+Gov_clarity_R+days_int_elec_R+corporatism+
                       pol_sophi_R+(1|countrycode)+(1|countryNAME), data=data, family=binomial(link="logit"), control=glmerControl(optimizer="bobyqa"))

ECO_modelPM=glmer(PM_vote ~ 1+eco_retro_R+mean_conflict_REV_R+
                    PID_3cat.f+age_R+female +PWindex_R+Insti_clarity_R+Gov_clarity_R+days_int_elec_R+corporatism+
                    pol_sophi_R+(1|countrycode)+(1|countryNAME), data=data, family=binomial(link="logit"), control=glmerControl(optimizer="bobyqa"))

ECO_modelPM.I=glmer(PM_vote ~ 1+eco_retro_R*mean_conflict_REV_R+
                      PID_3cat.f+age_R+female +PWindex_R+Insti_clarity_R+Gov_clarity_R+days_int_elec_R+corporatism+
                      pol_sophi_R+(1|countrycode)+(1|countryNAME), data=data, family=binomial(link="logit"), control=glmerControl(optimizer="bobyqa"))

ECO_modelJ=glmer(juniorPart_vote ~ 1+eco_retro_R+mean_conflict_REV_R+
                   PID_3cat.f+age_R+female +PWindex_R+Insti_clarity_R+Gov_clarity_R+days_int_elec_R+corporatism+
                   pol_sophi_R+(1|countrycode)+(1|countryNAME), data=data, family=binomial(link="logit"), control=glmerControl(optimizer="bobyqa"))

ECO_modelJ.I=glmer(juniorPart_vote ~ 1+eco_retro_R*mean_conflict_REV_R+
                     PID_3cat.f+age_R+female +PWindex_R+Insti_clarity_R+Gov_clarity_R+days_int_elec_R+corporatism+
                     pol_sophi_R+(1|countrycode)+(1|countryNAME), data=data, family=binomial(link="logit"), control=glmerControl(optimizer="bobyqa"))

screenreg(list(ECO_modelGOV,ECO_modelGOV.I, ECO_modelPM,ECO_modelPM.I,
               ECO_modelJ, ECO_modelJ.I), booktabs = TRUE, dcolumn = TRUE,digits=3)

htmlreg(list(ECO_modelGOV,ECO_modelGOV.I, ECO_modelPM,ECO_modelPM.I,
             ECO_modelJ, ECO_modelJ.I),
        custom.model.names = c("GOVERNMENT", "GOVERNMENT",
                               "PM", "PM",
                               "JUNIOR", "JUNIOR"),
        custom.coef.names = c("(Intercept)", "Negative economic perceptions", "Intra-government conflict",
                              "PM partisan", "Junior partisan","Opposition partisan", "Age",
                              "Female","Days in government", "Powell-Whitten index",  "Institutional clarity index",
                              "Government clarity index", "Corporatism", "Political sophistication", "Perceptions x conflict"),
        reorder.coef = c(2:3, 15, 4:6, 9:13,  7:8, 14, 1), booktabs = TRUE, dcolumn = TRUE,
        groups = list("Controls" = 4:11, "Demographics" = 12:14), 
        file = "tableS11.doc",digits=3)



###############
#  TABLE S12	#
###############

data$eco_retro_PURGED_R<-rescale(data$eco_retro_PURGED, "full")
summary(data$eco_retro_PURGED_R)


ECO_modelGOV=glmer(gov_vote ~ 1+eco_retro_PURGED_R+mean_conflict_REV_R+
                     PID_3cat.f+age_R+female +PWindex_R+Insti_clarity_R+Gov_clarity_R+days_int_elec_R+
                     pol_sophi_R+(1|countrycode)+(1|countryNAME), data=data, family=binomial(link="logit"), control=glmerControl(optimizer="bobyqa"))

ECO_modelGOV.I=glmer(gov_vote ~ 1+eco_retro_PURGED_R*mean_conflict_REV_R+
                       PID_3cat.f+age_R+female +PWindex_R+Insti_clarity_R+Gov_clarity_R+days_int_elec_R+
                       pol_sophi_R+(1|countrycode)+(1|countryNAME), data=data, family=binomial(link="logit"), control=glmerControl(optimizer="bobyqa"))

ECO_modelPM=glmer(PM_vote ~ 1+eco_retro_PURGED_R+mean_conflict_REV_R+
                    PID_3cat.f+age_R+female +PWindex_R+Insti_clarity_R+Gov_clarity_R+days_int_elec_R+
                    pol_sophi_R+(1|countrycode)+(1|countryNAME), data=data, family=binomial(link="logit"), control=glmerControl(optimizer="bobyqa"))

ECO_modelPM.I=glmer(PM_vote ~ 1+eco_retro_PURGED_R*mean_conflict_REV_R+
                      PID_3cat.f+age_R+female +PWindex_R+Insti_clarity_R+Gov_clarity_R+days_int_elec_R+
                      pol_sophi_R+(1|countrycode)+(1|countryNAME), data=data, family=binomial(link="logit"), control=glmerControl(optimizer="bobyqa"))


ECO_modelJ=glmer(juniorPart_vote ~ 1+eco_retro_PURGED_R+mean_conflict_REV_R+
                   PID_3cat.f+age_R+female +PWindex_R+Insti_clarity_R+Gov_clarity_R+days_int_elec_R+
                   pol_sophi_R+(1|countrycode)+(1|countryNAME), data=data, family=binomial(link="logit"), control=glmerControl(optimizer="bobyqa"))

ECO_modelJ.I=glmer(juniorPart_vote ~ 1+eco_retro_PURGED_R*mean_conflict_REV_R+
                     PID_3cat.f+age_R+female +PWindex_R+Insti_clarity_R+Gov_clarity_R+days_int_elec_R+
                     pol_sophi_R+(1|countrycode)+(1|countryNAME), data=data, family=binomial(link="logit"), control=glmerControl(optimizer="bobyqa"))

screenreg(list(ECO_modelGOV,ECO_modelGOV.I, ECO_modelPM,ECO_modelPM.I,
               ECO_modelJ, ECO_modelJ.I), booktabs = TRUE, dcolumn = TRUE,digits=3)

htmlreg(list(ECO_modelGOV,ECO_modelGOV.I, ECO_modelPM,ECO_modelPM.I,
             ECO_modelJ, ECO_modelJ.I),
        custom.model.names = c("GOVERNMENT", "GOVERNMENT",
                               "PM", "PM",
                               "JUNIOR", "JUNIOR"),
        custom.coef.names = c("(Intercept)", "Negative economic perceptions", "Intra-government conflict",
                              "PM partisan", "Junior partisan","Opposition partisan", "Age",
                              "Female","Days in government", "Powell-Whitten index",  "Institutional clarity index",
                              "Government clarity index", "Political sophistication", "Perceptions x conflict"),
        reorder.coef = c(2:3, 14, 4:6, 9:12,  7:8, 13, 1), booktabs = TRUE, dcolumn = TRUE,
        groups = list("Controls" = 4:10, "Demographics" = 11:13), 
        file = "tableS12.doc",digits=3)



###############
#  TABLE S13	#
###############

ECO_modelPM.w=glmer(PM_vote ~ 1+eco_retro_PURGED_R+mean_conflict_REV_R+cat_responsability_PM+
                      PID_3cat.f+age_R+female +PWindex_R+Insti_clarity_R+Gov_clarity_R+days_int_elec_R+
                      pol_sophi_R+(1|countrycode)+(1|countryNAME), data=data, family=binomial(link="logit"), control=glmerControl(optimizer="bobyqa"))

ECO_modelPM.3=glmer(PM_vote ~ 1+eco_retro_PURGED_R*mean_conflict_REV_R*cat_responsability_PM+
                      PID_3cat.f+age_R+female +PWindex_R+Insti_clarity_R+Gov_clarity_R+days_int_elec_R+
                      pol_sophi_R+(1|countrycode)+(1|countryNAME), data=data, family=binomial(link="logit"), control=glmerControl(optimizer="bobyqa"))

ECO_modelJ.w=glmer(juniorPart_vote ~ 1+eco_retro_PURGED_R+mean_conflict_REV_R+cat_responsability_J+
                     PID_3cat.f+age_R+female +PWindex_R+Insti_clarity_R+Gov_clarity_R+days_int_elec_R+
                     pol_sophi_R+(1|countrycode)+(1|countryNAME), data=data, family=binomial(link="logit"), control=glmerControl(optimizer="bobyqa"))

ECO_modelJ.3=glmer(juniorPart_vote ~ 1+eco_retro_PURGED_R*mean_conflict_REV_R*cat_responsability_J+
                     PID_3cat.f+age_R+female +PWindex_R+Insti_clarity_R+Gov_clarity_R+days_int_elec_R+
                     pol_sophi_R+(1|countrycode)+(1|countryNAME), data=data, family=binomial(link="logit"), control=glmerControl(optimizer="bobyqa"))

screenreg(list(ECO_modelPM.w,ECO_modelPM.3, ECO_modelJ.w, ECO_modelJ.3), digits=3, booktabs = TRUE, dcolumn = TRUE)


htmlreg(list(ECO_modelPM.w, ECO_modelPM.3, ECO_modelJ.w, ECO_modelJ.3),
        custom.model.names = c("PM", "PM",
                               "JUNIOR", "JUNIOR"),
        custom.coef.names = c("(Intercept)", "Negative economic perceptions", "Intra-government conflict",
                              "PM responsability", 
                              "PM partisan", "Junior partisan","Opposition partisan", "Age",
                              "Female","Days in government", "Powell-Whitten index",  "Institutional clarity index",
                              "Government clarity index", "Political sophistication", "Perceptions x conflict",
                              "Perceptions x PM responsability", "Conflict x PM responsability", 
                              "Perceptions x conflict x PM responsability",
                              "Junior responsability", "Perceptions x Junior responsability",
                              "Conflict x Junior responsability", "Perceptions x conflict x Junior responsability"),
        reorder.coef = c(2:4, 15:22, 5:7, 10:13, 8:9, 14, 1), booktabs = TRUE, dcolumn = TRUE,
        groups = list("Controls" = 12:18, "Demographics" = 19:21),file = "tableS13.doc", digits=3)









